using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
    using System.Globalization;
	#endregion
	public partial class AdminController: BaseController
	{
        public ActionResult Revenue()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_REVENUE,
            };
            return View(CreateViewModel(data));
        }

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Revenue(FormCollection forms)
        {
            CultureInfo info = new CultureInfo("en");
            var from = forms.GetValues("Revenue_From")[0];
            var to = forms.GetValues("Revenue_To")[0];
            var data = new DataTransferViewModel
            {
                From = DateTime.Parse(from, info),
                To = DateTime.Parse(to, info),
                EnumViewModelType = EnumViewModel.ADMIN_ORDERS_REVENUE_EXECUTE,
            };
            return View("Revenue", CreateViewModel(data));
        }

        public ActionResult SelectOrderDetail(string idorder, string from, string to)
        {
            var data = new DataTransferViewModel
            {
                IDDonDatHang = int.Parse(idorder),
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
            };
            return View("Revenue", CreateViewModel(data));
        }

        public ActionResult EditOrders(string idorder, string from, string to)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
                IDDonDatHang = int.Parse(idorder),
                IntID = int.Parse(idorder),
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
            };
            return View("EditOrders", CreateViewModel(data));
        }

        public ActionResult CancelEditingOrders(string idorder, string from, string to)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
                IDDonDatHang = int.Parse(idorder),
                IntID = int.Parse(idorder),
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
            };
            return View("Revenue", CreateViewModel(data));
        }

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdateOrders(FormCollection forms)
        {
            var from = forms.GetValues("Orders_From")[0];
            var to = forms.GetValues("Orders_To")[0];
            var shippdate = forms.GetValues("Orders_NgayGiaoHang")[0];

            var orders = _repDonDatHang.SelectByID(int.Parse(forms.GetValues("Orders_ID")[0]));
            orders.DaXacNhan = bool.Parse(forms.GetValues("IsVerified")[0]);
            orders.DaGiaoHang = bool.Parse(forms.GetValues("IsShipped")[0]);
            if (!string.Empty.Equals(shippdate))
            {
                orders.NgayGiaoHang = DateTime.Parse(shippdate);
            }

            var result = _repDonDatHang.Save();

            var data = new DataTransferViewModel
            {
                IDDonDatHang = orders.ID,
                From = DateTime.Parse(from),
                To = DateTime.Parse(to),
                EnumViewModelType = EnumViewModel.ADMIN_ORDERDETAIL,
            };
            return View("Revenue", CreateViewModel(data));
        }
	}
}